<%--
  Created by IntelliJ IDEA.
  User: hp
  Date: 2019/1/15
  Time: 9:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>销量统计</title>
</head>
<jsp:include page="${pageContext.request.contextPath}/common/tag.jsp"/>
<body style="">
    <div style="margin-top: 50px;">
        <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
        <div id="main" style="width: 600px;height:400px;float: left;"></div>
        <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
        <div id="member" style="width: 600px;height:400px;float:left;margin-left: 300px;"></div>
    </div>

</body>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    $.post('${pageContext.request.contextPath}/tongji/query',function (data) {
        console.log(data);
        var shopname = new Array();
        var num = new Array();
        $.each(data.xslist,function () {
            shopname.push(this.shopName);
            num.push(this.num);
        })
        option = {
            title: {
                text: '销量前十的商品'
            },
            color: ['#3398DB'],
            tooltip : {
                trigger: 'axis',
                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis : [
                {
                    type : 'category',
                    data : shopname,
                    axisTick: {
                        alignWithLabel: true
                    },
                    axisLabel: {
                        interval:0,
                        rotate:40
                    }
                }
            ],
            yAxis : [
                {
                    type : 'value'
                }
            ],
            series : [
                {
                    name:'销售数量',
                    type:'bar',
                    barWidth: '60%',
                    data:num
                }
            ]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
       /* console.log("名称"+shopname)
        console.log("数量"+num)*/
    })

    $.post("${pageContext.request.contextPath}/tongji/membersex",function (data) {
        var rs = [];
        $.each(data,function () {
            rs.push({
                name :this.sex,
                value:this.num
            });
        });
        console.log(rs);
        // 基于准备好的dom，初始化echarts实例
        var member = echarts.init(document.getElementById('member'));
        option = {
            title : {
                text: '客户性别统计',
                x:'center'
            },
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: data.sex
            },
            series : [
                {
                    name: '性别',
                    type: 'pie',
                    radius : '55%',
                    center: ['50%', '60%'],
                    data:rs,
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        // 使用刚指定的配置项和数据显示图表。
        member.setOption(option);
    })



</script>
</html>
